<style lang="scss">
  .d2m {
    .el-dialog__body {
      padding: 10px 20px;
      .el-select {
        width: 100%;
      }
    }
  }
</style>
<template>
  <el-dialog
    title="转换为度量"
    :visible.sync="dialogVisible"
    width="30%" :append-to-body="true" class="d2m">
    <el-form ref="dTomForm" :model="form" label-position="top" :rules="rules"
             @submit.prevent="onSubmit('projectForm')" onsubmit="return false">
      <el-form-item label="计算方法" prop="currentFunctionName">
        <el-select size="small" v-model="form.currentFunctionName" placeholder="请选择">
          <el-option :label="fun.title" :value="fun.name" :key="fun.name" v-for="fun in aggregateFunList">
          </el-option>
        </el-select>
      </el-form-item>


    </el-form>

    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="save">确 定</el-button>
  </span>
  </el-dialog>
</template>

<script>
  import {http, measure, dimension, field} from '@/resources';

  export default {
    data() {
      return {
        dialogVisible: false,
        form: {
          currentFunctionName: ''
        },
        rules: {
          currentFunctionName: [
            {required: true, message: '方法名', trigger: 'blur'}
          ]
        }
      };
    },
    name: 'dTomDialog',
    props: {
      show: {
        type: Boolean,
        default: false
      },
      fieldId: {
        type: String
      }
    },
    mounted() {

    },
    computed: {
      aggregateFunList: function () {
        return this.$store.state.aggregateFunList;
      },
      fieldType() {
        let type = '';
        if (this.fieldId) {
          type = this.fieldId.substr(0, 1);
        }
        return type;
      }
    },
    watch: {
      show: function (flag) {
        if (flag) {
          this.dialogVisible = true;
        }
      },

      fieldId: {
        handler: function () {
          this.getField();
        }
      },
      dialogVisible: function (flag) {
        if (!flag) {
          this.$emit('close');
        }
      }
    },
    methods: {
      getField() {
        if (this.fieldType === 'm') {
          measure.get(this.fieldId).then(res => {
            // this.currentFunctionName =
          });
        }
      },
      save() {
        this.$refs['dTomForm'].validate((valid) => {
          if (!valid) {
            return false;
          }
          // measure;
          // dimension.save()
          this.dialogVisible = false;
        });
      }
    }
  };
</script>
